Skip to content

feat: support relative URI resolution in $dynamicRef (#2928)#2945

Merged
baywet merged 3 commits into
microsoft:mainfrom
aqeelat:feat/dynamicref-relative-uris
Jul 15, 2026
Merged

feat: support relative URI resolution in $dynamicRef (#2928)#2945
baywet merged 3 commits into
microsoft:mainfrom
aqeelat:feat/dynamicref-relative-uris

Conversation

@aqeelat

@aqeelat aqeelat commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves #2928.

Extends cross-document $dynamicRef resolution to support relative URIs (e.g. external.yaml#node). Previously only absolute URIs worked.

Changes

  • Deserializers (V31+V32): Set ExternalResource on non-fragment $dynamicRef references so the workspace loader can discover and fetch external documents automatically.
  • OpenApiWorkspace.ResolveDynamicRef: Resolve relative URIs against the host document BaseUri before calling FindDocumentByBaseUri.
  • Tests: 17 missing V32 test mirrors added for full parity with V31. Fixed dead fallback in cross-document tests.

Depends on

#2913 (merged in eacc2fc0)

aqeelat added 2 commits July 14, 2026 15:22
Set ExternalResource on non-fragment $dynamicRef references so the
workspace loader can discover and fetch external documents. Resolve
relative URIs against hostDocument.BaseUri in Target before calling
FindDocumentByBaseUri.

Tests:
- Fragment-only: ExternalResource is null
- Absolute URI: ExternalResource is set, resolves across documents
- Relative URI: ExternalResource is set, resolves against BaseUri across documents
- V31 and V32 coverage
Adds 17 missing V32 test mirrors for full parity with V31 coverage.
Replaces dead '?? new OpenApiWorkspace()' fallback with null-forgiving
'!' in both V31 and V32 cross-document tests.
@aqeelat aqeelat requested a review from a team as a code owner July 14, 2026 14:52
@aqeelat

aqeelat commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@baywet the actual change is in the first commit. the second commit is just mirroring the tests between V31 and V32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for resolving cross-document $dynamicRef values that use relative URIs by (1) capturing the external resource on deserialization so the workspace loader can fetch it, and (2) resolving relative document URIs against the host document BaseUri during $dynamicRef resolution.

Changes:

  • Populate Reference.ExternalResource for non-fragment $dynamicRef during V3.1/V3.2 schema deserialization.
  • Update OpenApiWorkspace.ResolveDynamicRef to resolve relative $dynamicRef document URIs against hostDocument.BaseUri before lookup.
  • Expand V3.2 dynamic-ref test coverage to mirror V3.1 and add cross-document relative URI resolution tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDynamicRefTests.cs Adds/extends V3.2 tests, including cross-document relative $dynamicRef resolution and parity coverage.
test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDynamicRefTests.cs Adds assertions/coverage for ExternalResource and a V3.1 cross-document relative $dynamicRef test.
src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs Resolves relative $dynamicRef document URIs against BaseUri before document lookup (and updates docs).
src/Microsoft.OpenApi/Reader/V32/OpenApiSchemaDeserializer.cs Sets externalResource for $dynamicRef schema references (V3.2).
src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs Sets externalResource for $dynamicRef schema references (V3.1).

Comment thread src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs Outdated
Comment thread src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs
baywet
baywet previously approved these changes Jul 15, 2026

@baywet baywet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!
LGTM, besides copilot's comments.

@baywet baywet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

@baywet baywet enabled auto-merge (squash) July 15, 2026 16:14
@baywet baywet merged commit 821053b into microsoft:main Jul 15, 2026
9 checks passed
baywet added a commit that referenced this pull request Jul 15, 2026
feat: support relative URI resolution in $dynamicRef (#2928) (#2945)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support relative URI resolution in $dynamicRef

3 participants